<template>
  <div>
	<el-dialog title="登陆" :visible.sync="loginVisible" center width="30%">
		<el-form :model="user" status-icon label-width="60px" class="demo-ruleForm">
			<el-form-item label="手机号" prop="num">
				<el-input v-model.number="user.username"></el-input>
			</el-form-item>
			<el-form-item label="密码" prop="pass">
				<el-input type="password" v-model="user.password" auto-complete="off"></el-input>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="loginVisible = false">取 消</el-button>
			<el-button type="primary" @click="login">登 录</el-button>
		</div>
	</el-dialog>
	
	<el-dialog title="注册" :visible.sync="regVisible" center width="30%">
		<el-form :model="regUser" status-icon label-width="60px" class="demo-ruleForm">
			<el-form-item label="手机号" prop="num">
				<el-input v-model.number="regUser.phone"></el-input>
			</el-form-item>
			<el-form-item label="验证码" prop="num">
				<el-input v-model.number="regUser.code" style="width: 60%;"></el-input>
				<el-button style="width: 38%;">发送验证码</el-button>
			</el-form-item>
			<el-form-item label="用户名">
				<el-input v-model.number="regUser.name"></el-input>
			</el-form-item>
			<el-form-item label="密码" prop="pass">
				<el-input type="password" v-model="regUser.password" auto-complete="off"></el-input>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="regVisible = false">取 消</el-button>
			<el-button type="primary" @click="login">注 册</el-button>
		</div>
	</el-dialog>
  </div>
</template>
<script>
module.exports = {
    data: function() {
        return {
            user: {
				username:"13000000002",
				password:"123456"
			},
			regUser:{},
			loginVisible:false,
			regVisible:false
        }
    },
	methods: {
		showLogin:function(loginVisible) {
			if(loginVisible){
			    this.loginVisible = loginVisible
			}else {
			    this.loginVisible = true
			}
			//this.user={}
		},
		showReg:function(regVisible) {
			if(regVisible){
			    this.regVisible = regVisible
			}else {
			    this.regVisible = true
			}
			this.regUser={}
		},
        login:function(){
			this.user.utype='user'
			user_login(this.user).then(data=> {
//				Cookies.set('portal_access_token',data.access_token);
//				Cookies.set('portal_access_name',data.username);
//				if (VUE_APP_SERVER_DOMAIN) {
					Cookies.set('portal_access_token',data.access_token, { domain: VUE_APP_SERVER_DOMAIN })
					Cookies.set('portal_access_name',data.username, { domain: VUE_APP_SERVER_DOMAIN })
					Cookies.set('portal_access_phone',this.user.username, { domain: VUE_APP_SERVER_DOMAIN })
//				}
				location.reload();
			})
        }
    },
	mounted() {
		window.showLogin = this.showLogin;
		window.showReg = this.showReg;
	}
}
</script>